<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>区间涨幅</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">				
			.fixedBox{					
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}	
			<!-- input[type=number]::-webkit-inner-spin-button,  -->
			<!-- input[type=number]::-webkit-outer-spin-button { -->
			  <!-- opacity: 0; -->
			<!-- } -->
			input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{
					-webkit-appearance:none;
			}
			input[type="number"]{
				-moz-appearance: textfield; 
			}
	
			table{
				width:100px; 
				border-collapse:collapse; 
				text-align:center;
			}
			td,th{border:1px solid #696969}
			th { 
				color:#E5E5E5;  <!-- 表头文字颜色 -->
			}
			td a:link{
				color:#E5E5E5;  <!-- 列表文字颜色 -->
			}			
		</style>
	</head>
	<body>					
		<div id="title"></div>
		<div id="towriteb" class="fixedBox" style="border:2px solid #000;display:none;">			
			<div id="towrite1" class="fixedBox" style="position:relative; float:left;"></div>
			<div id="towrite2" class="fixedBox" style="position:relative; float:left;margin-left:10px;"></div>
		</div>	
		<div id="towriteg" class="fixedBox" style="display:none;"></div>
		<!-- <input size=2 maxlength=2 value=1 id="payCnt" οnkeyup=Num(this) style="text-align: center;" > -->
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
			var bkcolor = $("body").css("backgroundColor");
			var thcolor = "";
			var tdcolor = "";			
			window.onload = function() {				
				changeStyle();
				getSource(1);				
			}
			
			function load(name) {
				var xhr = new XMLHttpRequest()							
				okStatus = document.location.protocol === "file:" ? 0 : 200;				
				xhr.open('GET', name, false);
				xhr.overrideMimeType("text/html;charset=gb2312");//默认为utf-8				
				xhr.send(null);
				return xhr.status === okStatus ? xhr.responseText : null;
			}
			
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {					
					getSource(fp);
					if(ssbg != ""){
						getbkgg(ssbg);
					}					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
					time_range("9:00","15:15")
				},
				60000);
			})
			
			function changeStyle() {
				var obj = document.getElementById("title");								
				obj.style.left= "0px"; 				
				obj.style.width= "760px";	
				obj.style.height= "20px";
				
				var obja = document.getElementById("towriteb");
				//obja.style.top= "10px";
				obja.style.marginTop= "25px"; 
				obja.style.left= "18px"; 				
				obja.style.width= "950px";	
				//obja.style.height= "720px";
				obja.style.fontSize="12px";
				obja.style.display= "none";
				
				var objb = document.getElementById("towriteg");	//个股
				objb.style.top= "37px";
				objb.style.left= "20px"; 				
				objb.style.width= "600px";	
				objb.style.height= "720px";
				objb.style.fontSize= "12px";
				//objb.style.display= "none";
				
				var obj1 = document.getElementById("towrite1");					
				obj1.style.left= "-10px"; 
				obj1.style.width= "380px";
				obj1.style.marginTop= "-10px"; 
				//obj1.style.height= "500px";
				obj1.style.fontSize="12px";
				
				var obj2 = document.getElementById("towrite2");				
				obj2.style.left= "-10px"; 
				obj2.style.width= "520px";
				obj2.style.marginTop= "-10px"; 
				//obj2.style.height= "500x";
				obj2.style.fontSize="12px";	  		  			  
			}		
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			function NumberTransform(num) { 
				var result = parseFloat(num);
				if (isNaN(result)) {                    
                   return false;  
               }  				
               if(Math.abs(result) > 100000000){
				result = result / 100000000;
				result = result.toFixed(2) + "亿";
			   }else if(Math.abs(result) > 10000){
			    result = result/10000;
				result = result.toFixed(0) + "万";
			   }
               return result;  
			};
			
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){				
					if(alist[i] == undefined){
						break;
					}
					alist[i].style.color = "#E5E5E5"; //给所有a标签赋原色
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}
			
			
			var tz1 = 5;
			var tz2 = 5;
			var tz3 = 5;
			function addInputWithAdjustBtn(inputId) {
				var inputObj = document.getElementById(inputId);
				var height = inputObj.offsetHeight + "px";
				//var width = (inputObj.offsetWidth / 2) + "px";
				var width = (inputObj.offsetWidth * 0.7) + "px";
				var button_reduce = document.createElement("input");
				button_reduce.type='button';
				button_reduce.value='-';
				button_reduce.id='reduce_btn_' + inputId;
				button_reduce.style.marginLeft= "10px";
				button_reduce.style.width= width;
				button_reduce.style.height = height;
				var button_add = document.createElement("input");
				button_add.type='button';
				button_add.value='+';
				button_add.id='add_btn_' + inputId;
				button_add.style.width= width;
				button_add.style.height = height;
				inputObj.parentNode.insertBefore(button_reduce,inputObj);
			　	inputObj.parentNode.insertBefore(button_add,inputObj.nextSibling);
			　    
				addEvent(button_reduce,'click',function(){
					var num_reduce = parseInt($("#"+inputId).val()) - 1;
					if (num_reduce > 0) {
						$('#'+inputId).val(num_reduce);
						if(inputId == "val1"){
							tz1 = $("#val1").val();
							getgg(4);
						}else if(inputId == "val2"){
							tz2 = $("#val2").val();
							getbk(4);
						}else if(inputId == "val3"){
							tz3 = $("#val3").val();
							if(ssbg != ""){
								var aa = ssbg.split("#");
								var bb = aa[0] + "#" + aa[1] + "#" + "4";
								getbkgg(bb);
							}		
						}					
					}
					
				});
				
				addEvent(button_add,'click',function(){
					var num_add = parseInt($("#"+inputId).val()) + 1;
					if (num_add <= 100) {
						$('#'+inputId).val(num_add);
						if(inputId == "val1"){
							tz1 = $("#val1").val();
							getgg(4);
						}else if(inputId == "val2"){
							tz2 = $("#val2").val();
							getbk(4);
						}else if(inputId == "val3"){
							tz3 = $("#val3").val();
							if(ssbg != ""){
								var aa = ssbg.split("#");
								var bb = aa[0] + "#" + aa[1] + "#" + "4";
								getbkgg(bb);
							}		
						}					
					}
				});
			};

			function addEvent(el, type, myFunction) {
				if(el.addEventListener){  //所有主流浏览器，除了 IE 8 及更早 IE版本
					el.addEventListener(type,myFunction);
				}else if(el.attachEvent()){   // IE 8 及更早 IE 版本
					el.attachEvent('on' + type,myFunction);
				}else{
				　return false;
				}
			};

			var zfs = [];	
			function getzf(dms) {
				var url = "http://qt.gtimg.cn/q=" + dms;
				zfs = [];
				var aa = ""
				$.ajax({
					type: "get",
					url: url,
					dataType: "text",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(data);							
						var ss = data.replace(/(")|(=)/g,'').split(';');						
						for (var i = 0; i < ss.length - 1; i++){
							var aa = ss[i].split("~")
							zfs.push({"code":aa[2],"name":aa[1],"xj":aa[3],"zf":aa[32],"hsl":aa[38]});
						}
					}
				});
			}
				
			var fp = 1;
			function getSource(p) {		
				fp = p;
				var div = document.getElementById('title');				
				var a1 = "<a style='position:absolute; left:100px;font-size:14px;' href='javascript:void(0)' id='qj1' onclick='getSource(1)'>" + "按个股" + "</a>";	
				var a2 = "<a style='position:absolute; left:160px;font-size:14px;' href='javascript:void(0)' id='qj2' onclick='getSource(2)'>" + "按板块" + "</a>";
				var qh = "<a style='position:absolute; left:500px;font-size:12px;' href='javascript:void(0)' onclick='clearstorage()'>" + "清除缓存" + "</a>";
				div.innerHTML = "<font>区间涨幅</font>" + a1 + a2 + qh;	
				
				var Obj = document.getElementById('qj' + p);				
				Obj.style.color = "#FFA07A"; 
				
				if(p == 1){
					getgg(fsg);
				}else if(p == 2){
					getbk(fsb);
				}
			}
			
			var fxg = "1";
			var fsg = 0;
			var flg = "2";
			var bk = 0;
			function getgg(p) {  //按个股
				//alert(p)					
				var div = document.getElementById('towriteg');
				div.style.display = "block";
				var divb = document.getElementById('towriteb');	
				divb.style.display = "none";
				
				if(fsg != p){  //切换类别 清零
					fxg = 1;
					flg = "2";
				}
				fsg = p;
				
				var p1 = "<a href='javascript:void(0)' id='gpx0' onclick='getgg(" + "0" + ")'>" + "5日" + "</a>";	
				var p2 = "<a href='javascript:void(0)' id='gpx1' onclick='getgg(" + "1" + ")'>" + "10日" + "</a>";
				var p3 = "<a href='javascript:void(0)' id='gpx2' onclick='getgg(" + "2" + ")'>" + "20日" + "</a>";
				var p4 = "<a href='javascript:void(0)' id='gpx3' onclick='getgg(" + "3" + ")'>" + "60日" + "</a>";					
				
				var n = 5;				
				if(p == 1){
					n = 10;
				}else if(p == 2){
					n = 20;
				}else if(p == 3){
					n = 60;
				}else if(p == 4){
					n = tz1;
				}
				
				updated(n);	
				
				div.innerHTML = "<p>区间（ " + p1 + p2 + p3 + p4 + "）<font color=#FFFACD>&nbsp;&nbsp;" + st + "--" + et + '</font><font id="gpx4" style="margin-left:20px;">自定义区间</font><input type="number" style="width:25px;" id="val1" value=' + tz1 + ' min="1" max="100" step="1" /></p>';			
				addInputWithAdjustBtn("val1");
				
				if(p < 4){
					$("#val1").val(n);
				}
				
				var aObj = document.getElementById('gpx' + p);				
				aObj.style.color = "#FFA07A"; 
				
				var url = "http://127.0.0.1:8880/w1/api/index.php?Order=" + fxg + "&st=60&a=GetInterviewsByDateStock&c=StockLineData&DEnd=" + et + "&Index=0&DStart=" + st + "&apiv=w31&Type=" + flg; 
				var res = [];
				var dms = "";
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));														
						for (var i = 0; i < data.List.length; i++){
							var aa = data.List[i]; 
							var code = aa[0];
							var name = aa[1];
							if(name.indexOf('ST') == -1 && code.substr(0,3) != "688"){	//过滤ST、科创板								
								if(code.substr(0,1) == "6"){
									dms += "sh" + code + ",";
								}else{
									dms += "sz" + code + ",";
								}								
								res.push({"code":code,"name":name,"zf":aa[3],"je":NumberTransform(aa[6]),"hs":keepTwoDecimal(aa[7]),"jlrts":aa[13],"bk":aa[10]});							
							}
						}						
					}
				});		
				
				getzf(dms);
				//alert(JSON.stringify(zfs));
				var res1 = [];
				for (var i = 0; i < res.length; i++){
					var code = res[i].code;
					var drzf = 0;
					var a = zfs.findIndex((v) => {    
						return v.code ===  code;
					});
					if(a > -1){
						var arrfind = zfs.find(function (item) {
							return item.code == code
						});
						drzf = arrfind.zf; 						
					}
					res1.push({"code":code,"name":res[i].name,"drzf":drzf,"zf":res[i].zf,"je":res[i].je,"hs":res[i].hs,"jlrts":res[i].jlrts,"bk":res[i].bk});																	
				}
				
				var json = res1;
					
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var v = 0;
				var b = 0;	
				var gl = "";  //高亮
				if(flg == "2"){
					gl = "涨幅";
				}else if(flg == "5"){
					gl = "净额";
				}else if(flg == "7"){
					gl = "换手";
				}else if(flg == "9"){
					gl = "净流入天数";
				}					
				for(var key in json[0]){  //表头													
					key = key.replace('code','代码').replace('name','名称').replace('drzf','当日涨幅%').replace('zf','涨幅%').replace('je','净额');
					key = key.replace('hs','换手%').replace('jlrts','净流入天数').replace('bk','板块');
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);	
					if(key == "当日涨幅%"){						
						th.style.color = "#FF80FF";							
					}
					if(key == "板块"){
						b = m;
						bk = m;
						th.style.color = "#FFA500";							
					}
					if(gl == key.replace("%","")){
						v = m;
						th.style.color = "#FF6633";	
						if(fxg == 0){
							th.style.color = "#ADFF2F";	
						}
					}
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;	
					var dm = "";
					var mc = "";					
					for(var key in json[i]){ //行元素遍历					
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm;
						}					
						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeTCss(this,\"" + dm + "\",\"towriteg\")'>" + rc + "</a>";
						
						if(p == 3){
							var qc = rc.toString();
							if(parseFloat(qc) >= 0){
								td.getElementsByTagName("a")[0].style.color = "#FF80FF";
							}
							if(parseFloat(qc) < 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}
												
						if(p == b + 1){							
							td.getElementsByTagName("a")[0].style.color = "#FFA500";															
						}
						if(p == v + 1){							
							td.getElementsByTagName("a")[0].style.color = "#FF6633";
							if(fxg == 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}
						
						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}	

				var div = document.getElementById("towriteg");
				
				div.appendChild(table);
				changeTable(table,'0');		//隐藏某列	指定隐藏的列，用#分割	
				table.style.marginTop = "10px";
				table.style.width = "580px"; 
				thcolor = $("th").css("color");				
				tdcolor = $("td a:first").css("color");		
				
				var table=div.getElementsByTagName("table")[0];
				makeSortable(table);			
				hover();					
			}
			
			//隐藏某列				
            function changeTable(table,ss) {	
				var trs = table.rows;
				ss = ss + '#';
				var aa = ss.split('#');
				for (var j = 0; j < aa.length; j++) {
					if(aa[j] != ""){
						for (var i = 0, len = trs.length; i < len; i++) {					
							var p = aa[j];
							var cell = trs[i].cells[p]; 
							cell.style.display = 'none';
						}
					}
				}					
			}
			
			var trid = "";
			function changeTCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementById("towriteg").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid){  //过滤选中行
								this.style.background = bkcolor;
							}else{
								this.style.background = "#483D8B";
							}
						}						
					}					
				}
			}	
			
			var pt = 0;
			var rs = 0;
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
							//alert(n);	
							
							if(n > 2 && n < 7){
								if(n == 3){
									flg = "2";															
								}else if(n == 4){
									flg = "5";							
								}else if(n == 5){
									flg = "7";							
								}else if(n == 6){
									flg = "9";							
								}
								if(rs != n){  //切换列 清零
									rs = n;
									fxg = 0;
									pt = 1;
								}else{
									fxg = (pt%2 == 0) ? 0 : 1;
									pt++;
								}
								getgg(fsg);							
							}
							if(n < 3 || n > 6){
								showCol(n);		//高亮
							
								var tbody=table.tBodies[0];
								var rows=tbody.getElementsByTagName("tr");
								rows=Array.prototype.slice.call(rows,0);

								//基于第n个<td>元素的值对行排序
								rows.sort(function(row1,row2){
									headtxt = headers[n].textContent;								
									var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
									var cell2=row2.getElementsByTagName("td")[n];																
									var val1=cell1.textContent||cell1.innerText;//获得文本内容
									var val2=cell2.textContent||cell2.innerText;
									if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("板块") != -1){
										val1 = val1;
										val2 = val2;
									}else{
										val1 = parseFloat(val1);
										val2 = parseFloat(val2)
									}
									if(val1<val2){
										return -1;
									}else if(val1>val2){
										return 1;
									}else{
										return 0;
									}
									
								});
								if(flag){
									rows.reverse();								
								}
								
								for(var i=0;i<rows.length;i++){
									tbody.appendChild(rows[i]);
								}

								flag=!flag;	
							}							
						}
					}(i));
				}
			}
			
			function showCol(iCol){			
				var div = document.getElementById("towriteg");
				var oTable = div.getElementsByTagName('table')[0];
				for (i=0;i < oTable.rows.length; i++){										
					for (j=0;j < oTable.rows[0].cells.length; j++){
						oTable.rows[i].cells[j].style.color = thcolor;
						oTable.rows[i].cells[2].style.color = "#FF80FF";						
						oTable.rows[i].cells[bk].style.color = "#FFA500";						
					}
					oTable.rows[i].cells[iCol].style.color = "#FF6633";					
				}

				otagsA = oTable.getElementsByTagName("a");  //a变色
				for (i = 0; i < otagsA.length; i++) {
					otagsA[i].style.color = tdcolor;
					if(otagsA[i].id == 3){					
						var qc = otagsA[i].text;
						if(parseFloat(qc) >= 0){
							otagsA[i].style.color = "#FF80FF";
						}
						if(parseFloat(qc) < 0){
							otagsA[i].style.color = "#ADFF2F";
						}								
					}
					if(otagsA[i].id == bk + 1){
						otagsA[i].style.color = "#FFA500";								
					}
					if(otagsA[i].id == iCol + 1){
						otagsA[i].style.color = "#FF6633";
					}
				}								
			}
			
			var fxb = "1";
			var fsb = 0;
			var flb = "1";
			function getbk(p) {  //按板块
				//alert(p)
				//alert(tz1)
				var divg = document.getElementById('towriteg');
				divg.style.display = "none";
				var divb = document.getElementById('towriteb');	
				divb.style.display = "block";
				
				var div1 = document.getElementById('towrite1');	
				
				if(fsb != p){  //切换类别 清零
					fxb = 1;
					flb = "1"
				}
				fsb = p;
				var p1 = "<a href='javascript:void(0)' id='bpx0' onclick='getbk(" + "0" + ")'>" + "5日" + "</a>";	
				var p2 = "<a href='javascript:void(0)' id='bpx1' onclick='getbk(" + "1" + ")'>" + "10日" + "</a>";
				var p3 = "<a href='javascript:void(0)' id='bpx2' onclick='getbk(" + "2" + ")'>" + "20日" + "</a>";
				var p4 = "<a href='javascript:void(0)' id='bpx3' onclick='getbk(" + "3" + ")'>" + "60日" + "</a>";					
				//var div1 = document.getElementById('towrite1');	
				div1.innerHTML =  '<p>区间（ ' + p1 + p2 + p3 + p4 + '）<font id="bpx4" style="margin-left:5px;">自定义区间</font><input type="number" style="width:25px;" id="val2" value=' + tz2 + ' min="1" max="100" step="1" /></p>';			
				addInputWithAdjustBtn("val2");
				
				var aObj = document.getElementById('bpx' + p);				
				aObj.style.color = "#FFA07A"; 
							
				
				var n = 5;
				if(p == 1){
					n = 10;
				}else if(p == 2){
					n = 20;
				}else if(p == 3){
					n = 60;
				}else if(p == 4){
					n = tz2;
				}

				if(p < 4){
					$("#val2").val(n);
				}
				updated(n);
				
				var url = "http://127.0.0.1:8880/w1/api/index.php?Order=" + fxb + "&a=GetInterviewsByDateZS&st=30&c=StockLineData&DEnd=" + et + "&Index=0&DStart=" + st + "&apiv=w31&Type=" + flb; 
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));														
						for (var i = 0; i < data.List.length; i++){
							var aa = data.List[i]; 
							var code = aa[0];
							var name = aa[1];
							if(name.indexOf('ST') == -1 && code.substr(0,3) != "688"){	//过滤ST、科创板
								res.push({"code":code,"name":name,"zf":aa[2],"je":NumberTransform(aa[5]),"jlrts":aa[8]});							
							}
						}						
					}
				});		
				
				var json = res;
					
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var v = 0;
				var b = 0;					
				var gl = "";  //高亮
				if(flb == "1"){
					gl = "涨幅";
				}else if(flb == "3"){
					gl = "净额";					
				}else if(flb == "7"){
					gl = "净流入天数";
				}					
				for(var key in json[0]){  //表头													
					key = key.replace('code','代码').replace('name','名称').replace('zf','涨幅%').replace('je','净额').replace('jlrts','净流入天数');
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);					
					
					if(gl == key.replace("%","")){
						v = m;
						th.style.color = "#FF6633";	
						if(fxb == 0){
							th.style.color = "#ADFF2F";	
						}
					}
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;	
					var dm = "";
					var mc = "股票名称";					
					for(var key in json[i]){ //行元素遍历					
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm;
						}else if(p == 2){ 
							mc = rc;
							tr.innerHTML = tr.innerHTML.replace(/股票名称/g,mc);
						}							
						//td.innerHTML = "<a href='javascript:void(0)' id='" + p + "' onclick='getbkgg(\"" + dm + "#" + mc + "#" + fsbg + "\");changeCss(this,\"" + dm + "\",\"towrite1\")'>" + rc + "</a>";
						td.innerHTML = "<a href='javascript:void(0)' id='" + p + "' onclick='getbkgg(\"" + dm + "#" + mc + "\");changeCss(this,\"" + dm + "\",\"towrite1\")'>" + rc + "</a>";
						
						if(p == v + 1){							
							td.getElementsByTagName("a")[0].style.color = "#FF6633";
							if(fxb == 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}						
						tr.appendChild(td);
						p++;
					}
					
					tbody.appendChild(tr);
				}	

				var div = document.getElementById("towrite1");					
				div.appendChild(table);
				changeTable(table,'0');		//隐藏某列	指定隐藏的列，用#分割	
				table.style.width="100px";
				thcolor = $("th").css("color");				
				tdcolor = $("td a:first").css("color");		
				
				var table=div.getElementsByTagName("table")[0];
				makeSortableb(table);			
				hoverb();					
			}
			
			
			var trid1 = "";
			function changeCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}
				trid1 = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hoverb(){  //鼠标经过
				var rows = document.getElementById("towrite1").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid1){  //过滤选中行
								this.style.background = bkcolor;
							}else{
								this.style.background = "#483D8B";
							}
						}						
					}					
				}
			}	
			
			var ptb = 0;
			var rsb = 0;
			function makeSortableb(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
							//alert(n);	
							
							if(n > 1 && n < 5){
								if(n == 2){
									flb = "1";															
								}else if(n == 3){
									flb = "3";							
								}else if(n == 4){
									flb = "7";							
								}
								if(rsb != n){  //切换列 清零
									rsb = n;
									fxb = 0;
									ptb = 1;
								}else{
									fxb = (ptb%2 == 0) ? 0 : 1;							
									ptb++;
								}
								getbk(fsb);							
							}
							if(n < 2 || n > 4){
								showColb(n);		//高亮
							}
							//showColb(n);		//高亮
							var tbody=table.tBodies[0];
							var rows=tbody.getElementsByTagName("tr");
							rows=Array.prototype.slice.call(rows,0);

							//基于第n个<td>元素的值对行排序
							rows.sort(function(row1,row2){
								headtxt = headers[n].textContent;								
								var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
								var cell2=row2.getElementsByTagName("td")[n];																
								var val1=cell1.textContent||cell1.innerText;//获得文本内容
								var val2=cell2.textContent||cell2.innerText;
								<!-- if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("板块") != -1){ -->
									<!-- val1 = val1; -->
									<!-- val2 = val2; -->
								<!-- } -->
								if(val1<val2){
									return -1;
								}else if(val1>val2){
									return 1;
								}else{
									return 0;
								}
								
							});
							if(flag){
								rows.reverse();								
							}
							
							for(var i=0;i<rows.length;i++){
								tbody.appendChild(rows[i]);
							}

							flag=!flag;							
						}
					}(i));
				}
			}
			
			function showColb(iCol){			
				var div = document.getElementById("towrite1");
				var oTable = div.getElementsByTagName('table')[0];
				for (i=0;i < oTable.rows.length; i++){										
					for (j=0;j < oTable.rows[0].cells.length; j++){
						oTable.rows[i].cells[j].style.color = thcolor;						
					}
					oTable.rows[i].cells[iCol].style.color = "#FF6633";					
				}

				otagsA = oTable.getElementsByTagName("a");  //a变色
				for (i = 0; i < otagsA.length; i++) {
					otagsA[i].style.color = tdcolor;					
					if(otagsA[i].id == iCol + 1){
						otagsA[i].style.color = "#FF6633";
					}
				}								
			}
			
			
			var st = "";
			var et = "";
			function updated(p) {
				//alert(p);
				var t  = "";
				if(localStorage.getItem('jyrq') != null) {  //判断有无缓存
					t = localStorage.getItem('jyrq'); //取缓存
				}
				
				var url1 = "http://127.0.0.1:8880/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w21&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7"						
				var res1 = [];
				$.ajax({
					type: "get",
					url: url1,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));							
						et = data.Day.toString();
						if(t.indexOf(et) == -1){
							localStorage.setItem('jyrq', t + "," + et);  //交易日期写入缓存
						}
					}
				});	
				//alert(et)
				
				var day = new Date();				
				day.setTime(day.getTime());			
				var j = 0;
				for (i = 0; i < 500; i++){					
					if(i > 0){
						day.setTime(day.getTime() - 24*60*60*1000);
					}					
					st = day.Format("yyyy-MM-dd");
					var week = day.getDay();
					t = localStorage.getItem('jyrq'); //取缓存	
					if(week != 0 && week != 6){
						if(t.indexOf(st) > -1){
							j++;
						}else{
							var url2 = "http://127.0.0.1:8880/w1/api/index.php?Order=1&st=30&a=GetInterviewsByDateStock&c=StockLineData&DEnd=" + et + "&Index=0&DStart=" + st + "&apiv=w31&Type=2"							
							var res2 = [];
							$.ajax({
								type: "get",
								url: url2,
								dataType: "json",
								async : false,
								cache:false,
								timeout:3000,					
								success: function(data) {
									//alert(JSON.stringify(data))						
									//document.write(JSON.stringify(data));							
									res2 = data;						
								}
							});	
							if(res2.List.length > 0){
								localStorage.setItem('jyrq', t + "," + st);  //交易日期写入缓存
								j++;
							}				
						}
					}
					if(j == p){
						break;
					}					
				}								
				//alert(st);					
			}			
						
			var fxbg = "1";
			var fsbg = 0;
			var flbg = "2";
			var bkdm = "";
			var bkmc = "";
			var ssbg = "";
			var bk2 = 0;
			function getbkgg(ss) {  //板块个股
				//alert(fsbg)
				//alert(ss)
				var dms = ss.split('#');
				bkdm = dms[0];
				bkmc = dms[1];
				var p = fsbg;
				if(dms.length == 3){													
					p = dms[2];
				}
				//alert(p)
				ssbg = bkdm + "#" + bkmc + "#" + p;
				var div = document.getElementById('towrite2');	
				
				if(fsbg != p){  //切换类别 清零
					fxbg = 1;
					flbg = 2;
				}
				fsbg = p;
				var p1 = "<a href='javascript:void(0)' id='bgpx0' onclick='getbkgg(\"" + bkdm + "#" + bkmc + "#0\")'>" + "5日" + "</a>";
				var p2 = "<a href='javascript:void(0)' id='bgpx1' onclick='getbkgg(\"" + bkdm + "#" + bkmc + "#1\")'>" + "10日" + "</a>";
				var p3 = "<a href='javascript:void(0)' id='bgpx2' onclick='getbkgg(\"" + bkdm + "#" + bkmc + "#2\")'>" + "20日" + "</a>";
				var p4 = "<a href='javascript:void(0)' id='bgpx3' onclick='getbkgg(\"" + bkdm + "#" + bkmc + "#3\")'>" + "60日" + "</a>";					
				var tj = '<font id="bgpx4" style="margin-left:5px;">自定义区间</font><input type="number" style="width:25px;" id="val3" value=' + tz3 + ' min="1" max="100" step="1" />';
				div.innerHTML = "<p style='color:#FFFFF0;font-size:14px;'><strong>" + bkmc + "</strong><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;区间（" + p1 + p2 + p3 + p4 + "）</font>" + tj + "</p>";
				
				var aObj = document.getElementById('bgpx' + p);				
				aObj.style.color = "#FFA07A"; 
				
				var n = 5;
				if(p == 1){
					n = 10;
				}else if(p == 2){
					n = 20;
				}else if(p == 3){
					n = 60;
				}else if(p == 4){
					n = tz3;
				}
								
				updated(n);					
				div.innerHTML += "<p style='color:#FFFACD;margin:-10px 0px 3px 0px;'>" + st + "--" + et + "</p>";	
				addInputWithAdjustBtn("val3");
				
				if(p < 4){
					$("#val3").val(n);
				}
				
				//var url = "http://127.0.0.1:8880/w1/api/index.php?Order=" + fxbg + "&a=InterviewsByDate&st=30&c=ZhiShuRanking&PhoneOSNew=1&DEnd=" + et + "&Index=0&DStart=" + st + "&apiv=w31&Type=" + flbg + "&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + bkdm; 				
				var url1 = "http://127.0.0.1:8880/w1/api/index.php?Order=" + fxbg + "&a=InterviewsByDate&st=30&c=ZhiShuRanking&PhoneOSNew=1&DEnd=" + et + "&Index=0&DStart=" + st + "&apiv=w31&Type=" + flbg + "&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + bkdm; 				
				var url2 = "http://127.0.0.1:8881/w1/api/index.php?Order=" + fxbg + "&a=InterviewsByDate&st=30&c=ZhiShuRanking&PhoneOSNew=1&DEnd=" + et + "&Index=0&DStart=" + st + "&apiv=w31&Type=" + flbg + "&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + bkdm; 				
				var url = url1;
				if(n > 61){
					url = url2;
				}		
				
				var dms = "";
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))
						//document.write(JSON.stringify(data));
						for (var i = 0; i < data.List.length; i++){
							var aa = data.List[i]; 
							var code = aa[0];
							var name = aa[1];
							if(code.substr(0,1) == "6"){
								dms += "sh" + code + ",";
							}else{
								dms += "sz" + code + ",";
							}		
							res.push({"code":code,"name":name,"zf":aa[3],"je":NumberTransform(aa[6]),"hs":keepTwoDecimal(aa[7]),"jlrts":aa[13],"bk":aa[10]});							
						}						
					}
				});		
				
				getzf(dms);
				//alert(JSON.stringify(zfs));
				var res1 = [];
				for (var i = 0; i < res.length; i++){
					var code = res[i].code;
					var drzf = 0;
					var a = zfs.findIndex((v) => {    
						return v.code ===  code;
					});
					if(a > -1){
						var arrfind = zfs.find(function (item) {
							return item.code == code
						});
						drzf = arrfind.zf; 						
					}
					res1.push({"code":code,"name":res[i].name,"drzf":drzf,"zf":res[i].zf,"je":res[i].je,"hs":res[i].hs,"jlrts":res[i].jlrts,"bk":res[i].bk});																	
				}
				
				var json = res1;
						
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var v = 0;
				var b = 0;					
				var gl = "";  //高亮
				if(flbg == "2"){
					gl = "涨幅";
				}else if(flbg == "5"){
					gl = "净额";
				}else if(flbg == "7"){
					gl = "换手";
				}else if(flbg == "9"){
					gl = "净流入天数";
				}					
				for(var key in json[0]){  //表头													
					key = key.replace('code','代码').replace('name','名称').replace('drzf','当日涨幅%').replace('zf','涨幅%').replace('je','净额');
					key = key.replace('hs','换手%').replace('jlrts','净流入天数').replace('bk','板块');
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);					
					if(key == "当日涨幅%"){						
						th.style.color = "#FF80FF";							
					}
					if(key == "板块"){
						b = m;
						bk2 = m;
						th.style.color = "#FFA500";							
					}
					if(gl == key.replace("%","")){
						v = m;
						th.style.color = "#FF6633";	
						if(fxbg == 0){
							th.style.color = "#ADFF2F";	
						}
					}
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;	
					var dm = "";
					var mc = "";					
					for(var key in json[i]){ //行元素遍历					
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm;
						}					
						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss2(this,\"" + dm + "\",\"towrite2\")'>" + rc + "</a>";
						
						if(p == 3){
							var qc = rc.toString();
							if(parseFloat(qc) >= 0){
								td.getElementsByTagName("a")[0].style.color = "#FF80FF";
							}
							if(parseFloat(qc) < 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}
						
						if(p == b + 1){							
							td.getElementsByTagName("a")[0].style.color = "#FFA500";															
						}
						if(p == v + 1){							
							<!-- td.getElementsByTagName("a")[0].style.color = "#FF6633"; -->
							<!-- if(fxbg == 0){ -->
								<!-- td.getElementsByTagName("a")[0].style.color = "#ADFF2F"; -->
							<!-- } -->
							var qc = rc.toString();
							if(parseFloat(qc) >= 0){
								td.getElementsByTagName("a")[0].style.color = "#FF6633";
							}
							if(parseFloat(qc) < 0){
								td.getElementsByTagName("a")[0].style.color = "#ADFF2F";
							}
						}						
						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}	

				var div = document.getElementById("towrite2");					
				div.appendChild(table);
				changeTable(table,'0');		//隐藏某列	指定隐藏的列，用#分割
				//var table=div.getElementsByTagName("table")[0];
				makeSortable2(table);			
				hover2();					
			}
						
			var trid2 = "";
			function changeCss2(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}
				trid2 = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover2(){  //鼠标经过
				var rows = document.getElementById("towrite2").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid2){  //过滤选中行
								this.style.background = bkcolor;
							}else{
								this.style.background = "#483D8B";
							}
						}						
					}					
				}
			}	
			
			var pt2 = 0;
			var rs2 = 0;
			function makeSortable2(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
							//alert(n);	
							
							if(n > 2 && n < 7){
								if(n == 3){
									flbg = "2";															
								}else if(n == 4){
									flbg = "5";							
								}else if(n == 5){
									flbg = "7";							
								}else if(n == 6){
									flbg = "9";							
								}
								if(rs2 != n){  //切换列 清零
									rs2 = n;
									fxbg = 0;
									pt2 = 1;
								}else{
									fxbg = (pt2%2 == 0) ? 0 : 1;							
									pt2++;
								}								
								getbkgg(ssbg);
							}
							if(n < 3 || n > 6){
								showCol2(n);		//高亮
							
								var tbody=table.tBodies[0];
								var rows=tbody.getElementsByTagName("tr");
								rows=Array.prototype.slice.call(rows,0);

								//基于第n个<td>元素的值对行排序
								rows.sort(function(row1,row2){
									headtxt = headers[n].textContent;								
									var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
									var cell2=row2.getElementsByTagName("td")[n];																
									var val1=cell1.textContent||cell1.innerText;//获得文本内容
									var val2=cell2.textContent||cell2.innerText;
									if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("板块") != -1){
										val1 = val1;
										val2 = val2;
									}else{
										val1 = parseFloat(val1);
										val2 = parseFloat(val2)
									}
									if(val1<val2){
										return -1;
									}else if(val1>val2){
										return 1;
									}else{
										return 0;
									}
									
								});
								if(flag){
									rows.reverse();								
								}
								
								for(var i=0;i<rows.length;i++){
									tbody.appendChild(rows[i]);
								}

								flag=!flag;	
							}							
						}
					}(i));
				}
			}
			
			function showCol2(iCol){			
				var div = document.getElementById("towrite2");
				var oTable = div.getElementsByTagName('table')[0];
				for (i=0;i < oTable.rows.length; i++){										
					for (j=0;j < oTable.rows[0].cells.length; j++){
						oTable.rows[i].cells[j].style.color = thcolor;
						oTable.rows[i].cells[2].style.color = "#FF80FF";						
						oTable.rows[i].cells[bk2].style.color = "#FFA500";						
					}
					oTable.rows[i].cells[iCol].style.color = "#FF6633";					
				}

				otagsA = oTable.getElementsByTagName("a");  //a变色
				for (i = 0; i < otagsA.length; i++) {
					otagsA[i].style.color = tdcolor;
					if(otagsA[i].id == 3){					
						var qc = otagsA[i].text;
						if(parseFloat(qc) >= 0){
							otagsA[i].style.color = "#FF80FF";
						}
						if(parseFloat(qc) < 0){
							otagsA[i].style.color = "#ADFF2F";
						}								
					}
					if(otagsA[i].id == bk2 + 1){
						otagsA[i].style.color = "#FFA500";								
					}
					if(otagsA[i].id == iCol + 1){
						otagsA[i].style.color = "#FF6633";
					}
				}								
			}
			
			function clearstorage(){				
				if(localStorage.getItem('jyrq') != null){						
					localStorage.removeItem('jyrq'); //清除缓存localStorage
				}
				
				<!-- var day = new Date(); -->
				<!-- day.setTime(day.getTime());			 -->
				<!-- for (i = 1; i < 300; i++){																		 -->
					<!-- day.setTime(day.getTime() - 24*60*60*1000); -->
					<!-- var ts = day.Format("yyyy-MM-dd"); -->
					
					<!-- if(localStorage.getItem('bkld' + ts) != null){	 -->
					
						<!-- localStorage.removeItem('bkld' + ts); //清除缓存localStorage -->
					<!-- } -->
				<!-- } -->
				alert('清除完成');
			}
		</script>
	</body>
</html>